/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef E22_CONFIG_H
#define E22_CONFIG_H


/* Includes ------------------------------------------------------------------*/
#include "E22_BaseConfig.h"
#include "stm32F4xx.h"
#include "usart.h"


/* Exported constants --------------------------------------------------------*/
/* Using Grand unions */
#pragma anon_unions






#define RF1_MD0_Pin              GPIO_Pin_14
#define RF1_MD0_GPIO_Port        GPIOE
#define RF1_MD1_Pin              GPIO_Pin_15
#define RF1_MD1_GPIO_Port        GPIOE



#define LIDAR_USE_CODE 
#define USE_ISP





#define Receiver_SenderMessageLength 12
#define E22_SettingMessageLength 12

/* RF433 Base Config */
#define RF433_ADDR        (1001)
#define RF433_CHANNEL     (40)
#define RF433_NETID       E22_DEFAULT
#define RF433_UART_BPS    E22_UART_115200
#define RF433_UART_CHK    E22_UART_8N1
#define RF433_RF_BPS      E22_RF_BPS_4K8
#define RF433_RF_PACK     E22_RF_PACK_240
#define RF433_RSSI_NOISE  E22_RSSI_NOISE_OFF
#define RF433_RF_PWR      E22_RF_PWR_24DBM
#ifdef LIDAR_USE_CODE
#define RF433_RSSI_BYTES  E22_RSSI_BYTES_OFF
#endif
#ifdef RECEIVE_USE_CODE
#define RF433_RSSI_BYTES  E22_RSSI_BYTES_ON
#endif
#define RF433_TRAN        E22_TRAN_DIRECT
#define RF433_TRAN_RELAY  E22_TRAN_RELAY_OFF
#define RF433_LBT         E22_LBT_OFF
#define RF433_WOR         E22_WOR_SEND
#define RF433_WOR_PERIOD  E22_WOR_PERIOD_2000
#define RF433_CRYPT_H     E22_DEFAULT
#define RF433_CRYPT_L     E22_DEFAULT
#define RF433_START_ADDR  (0x00)
#define RF433_PACK_LEN    (0x09)


#define E22_CONFIG_FLAG   0

/* Exported macros -----------------------------------------------------------*/

/* RF MDx ModePin Setting */
#ifdef USE_ISP
#define MD0_LOW() GPIO_ResetBits(RF1_MD0_GPIO_Port,RF1_MD0_Pin)
#define MD0_HIGH() GPIO_SetBits(RF1_MD0_GPIO_Port,RF1_MD0_Pin)
#define MD1_LOW() GPIO_ResetBits(RF1_MD1_GPIO_Port,RF1_MD1_Pin)
#define MD1_HIGH() GPIO_SetBits(RF1_MD1_GPIO_Port,RF1_MD1_Pin)
#define E22_FucGroundInit \
{ \
	&E22_USART_IT_Register, \
	&E22_RF_Setting, \
	&E22_USART_ReBaudRate, \
	&huart6, \
}
#else
#define MD0_LOW() GPIO_ResetBits(RF_MD0_GPIO_Port,RF_MD0_Pin)
#define MD0_HIGH() GPIO_SetBits(RF_MD0_GPIO_Port,RF_MD0_Pin)
#define MD1_LOW() GPIO_ResetBits(RF_MD1_GPIO_Port,RF_MD1_Pin)
#define MD1_HIGH() GPIO_SetBits(RF_MD1_GPIO_Port,RF_MD1_Pin)

#define E22_FucGroundInit \
{ \
	&E22_USART_IT_Register, \
	&E22_RF_Setting, \
	&E22_USART_ReBaudRate, \
	&huart1, \
}
#endif

#define DLC_MD0_LOW() GPIO_ResetBits(DLC_RF_MD0_GPIO_Port,DLC_RF_MD0_Pin)
#define DLC_MD0_HIGH() GPIO_SetBits(DLC_RF_MD0_GPIO_Port,DLC_RF_MD0_Pin)
#define DLC_MD1_LOW() GPIO_ResetBits(DLC_RF_MD1_GPIO_Port,DLC_RF_MD1_Pin)
#define DLC_MD1_HIGH() GPIO_SetBits(DLC_RF_MD1_GPIO_Port,DLC_RF_MD1_Pin)

#define RF433_CONFIG_PACK { \
						   (uint8_t)E22_CMD_HEAD, \
						   (uint8_t)RF433_START_ADDR, \
						   (uint8_t)RF433_PACK_LEN, \
						   (uint8_t)(RF433_ADDR >> 8)&0xff, \
						   (uint8_t)(RF433_ADDR)&0xff, \
						   (uint8_t)RF433_NETID, \
						   (uint8_t)((RF433_UART_BPS&0x07) << 5)|((RF433_UART_CHK&0x03) << 3)|(RF433_RF_BPS&0x07), \
						   (uint8_t)((RF433_RF_PACK&0x03) << 6)|(RF433_RSSI_NOISE << 5)|(RF433_RF_PWR&0x03), \
						   (uint8_t)RF433_CHANNEL % E22_CHANNEL_MAX, \
						   (uint8_t)(RF433_RSSI_BYTES << 7)|(RF433_TRAN << 6)|(RF433_TRAN_RELAY << 5)|(RF433_LBT << 4)|(RF433_WOR << 3)|(RF433_WOR_PERIOD&0x03), \
						   (uint8_t)RF433_CRYPT_H, \
						   (uint8_t)RF433_CRYPT_L, \
						  }

							


/* Exported types ------------------------------------------------------------*/
typedef struct
{
	union
	{
		uint8_t E22_SettingMessage[E22_SettingMessageLength];
		struct
		{
			uint8_t Header;
			uint8_t Start_Address;
			uint8_t PackageLength;
			uint8_t Address_L;
			uint8_t Address_H;
			uint8_t NetID;
			uint8_t UART_BSP_CHK_RF_BPS;
			uint8_t RF_PACK_RSSI_RF_PWR;
			uint8_t Channal;
			uint8_t RSSI_TRAN_LBT_WOR_PERIOD;
			uint8_t Crypt_H;
			uint8_t Crypt_L;
		};
	};
}E22_Setting_t;







//typedef struct
//{
//	void(*E22_USART_IT_Register)(UART_HandleTypeDef* huartx);
//	void(*E22_RF_Setting)(uint16_t Address,uint8_t Channel);
//	void(*E22_USART_ReBaudRate)(uint32_t BaudRate);
//	UART_HandleTypeDef* E22_Register;
//}E22_Fuc;
void E22_RF_Setting(uint16_t Address,uint8_t Channel);
void E22_RF_Setting_Old(uint16_t Address,uint8_t Channel);
/* Exported variables --------------------------------------------------------*/
//extern E22_Fuc E22_Function;


/* End -----------------------------------------------------------------------*/
#endif
